#!/usr/bin/python
# -*- coding: utf-8 -*-

# inputdialog.py

import sys
from PyQt4 import QtGui
from PyQt4 import QtCore


class Example(QtGui.QWidget):

    def __init__(self):
        super(Example, self).__init__()

        self.initUI()

    def initUI(self):

        self.button = QtGui.QPushButton(u'登录', self)
        self.button.setFocusPolicy(QtCore.Qt.NoFocus)

        self.button.move(20, 20)
        self.connect(self.button, QtCore.SIGNAL('clicked()'),
            self.showDialog)
        self.setFocus()

        self.label = QtGui.QLineEdit(self)
        self.label.move(130, 22)

        self.setWindowTitle(u'我是标题')
        self.setGeometry(300, 300, 350, 80)


    def showDialog(self):
        text, ok = QtGui.QInputDialog.getText(self, u'登录框',
            u'用户名:')

        if ok:
            self.label.setText(str(text))


if __name__ == '__main__':

    app = QtGui.QApplication(sys.argv)
    ex = Example()
    ex.show()
    app.exec_()
